<?php
class kst_display_position_model extends MY_Model {
	var $model = 'kst_display_position_model';

	function getApp()
	{
		$ls_sql	=  "SELECT	NAMA_DISPLAY value,
							DISPLAY_TYPE display
					FROM	admin_primkokas.kst_display_position
					ORDER BY NAMA_DISPLAY";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();;;
		}else{
			return array();
		}
	}


function GetJSON2()
	{
		$ls_sql = " SELECT *
					FROM KST_DISPLAY_TYPE
					WHERE (UPPER(NAMA_DISPLAY) LIKE '%".strtoupper(post('keyword'))."%'
						  OR UPPER(KODE_DISPLAY) LIKE '%".strtoupper(post('keyword'))."%' )
						  ORDER BY ".(post('short')=='' ? 'NAMA_DISPLAY' : post('short'))." ".(post('order')=='' ? 'asc' : post('order'));
						  return json_encode($this->paging($ls_sql));
	}

	function GetJSON()
	{
		$ls_sql	= "	SELECT  *		
					FROM	KST_DISPLAY_POSITION
					WHERE 	NAMA_DISPLAY != '(None)' and
					(UPPER(DISPLAY_ID) LIKE '%".strtoupper(post('keyword'))."%' OR 
							UPPER(NAMA_DISPLAY) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'DISPLAY_ID' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('kst_display_position', $arr_data);

	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('kst_display_position', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_roleid){
		$result = $this->db->get_where('kst_display_position', array('NAMA_DISPLAY' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_roleid)
	{
		$result = $this->db->get_where('kst_display_position', array('DISPLAY_ID' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	 function DeleteSingle($arr_rule)
	 {
	 	try {
	 		if(	intval($this->get_data("SELECT COUNT(1) FROM KST_DISPLAY_POSITION WHERE DISPLAY_ID = '".$arr_rule['display_id']."'"))<=0)
	 		{
	 			return $this->error_delete.' [id: '.$arr_rule['display_id']."]<br />";
	 		}else{
	 			$this->db->delete('KST_DISPLAY_POSITION', array('display_id' => $arr_rule['display_id']));
	 			return '';
	 		}
	 	} catch(Exception $e) {
	 		return $e->getMessage();
	 	}
	 }
}
?>